package org.springblade.modules.admin.vo;

import cn.hutool.core.convert.Convert;
import lombok.Data;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.entity.MaintainPlanTemplate;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 维保签字日志VO
 * @author: Sharry
 * @createTime: 2023/5/8 18:12
 * @version: Version-1.0
 */
@Data
public class ElevatorSignLogVO {
	/**
	 * plan id
	 */
	private Long planId;

	private Date createTime;

	private String realNames;

	private String name;

	public void setName(String name) {
		if(Func.isNotEmpty(name) && name.contains("%")){
			List<String> strings = Func.toStrList(name);
			List<MaintainPlanTemplate> list = new ArrayList<>(10);
			for (String str :strings) {
				String[] split = str.split("%");
				MaintainPlanTemplate maintainPlanTemplate = new MaintainPlanTemplate();
				maintainPlanTemplate.setTemplateName(split[1]);
				maintainPlanTemplate.setSort(Convert.toInt(split[2],0));
				list.add(maintainPlanTemplate);
			}
			List<String> collect = list.stream().sorted(Comparator.comparing(MaintainPlanTemplate::getSort)).map(MaintainPlanTemplate::getTemplateName).collect(Collectors.toList());
			this.name = String.join(",",collect);
		}else {
			this.name = name;
		}
	}
}
